App({
  serverUrl: "http://127.0.0.1:8888",
    
  //设置用户信息到storage
  setGlobalUserInfo(user) {
    var timestamp = Date.parse(new Date()); //获取当前时间戳,毫秒
    var expiration = timestamp + 1000 * 60 * 60 * 24 *3;  //设置过期时间3天
    wx.setStorageSync("userInfo", user);
    wx.setStorageSync("expiration", expiration);
    wx.setStorageSync("hasLogin", true);
  },
  //从storage获取用户信息
  getGlobalUserInfo() {
    var timestamp = Date.parse(new Date()); //获取当前时间戳,毫秒
    var expiration = wx.getStorageSync("expiration");
    if (timestamp > expiration){  //过期
      this.delGlobalUserInfo();
      return false;
    }
    //未过期更新时间
    wx.setStorageSync("expiration", expiration + 1000 * 60 * 60 * 24 * 3);
    return wx.getStorageSync("userInfo");
  },
  //清除storage的用户信息
  delGlobalUserInfo(){
    wx.removeStorageSync("hasLogin");
    wx.removeStorageSync("userInfo");
  },

  //保存用户的登录状态
  setHasLogin(){
    
  },

  //获取用户的登录状态
  getHasLogin(){
    var hasLogin = wx.getStorageSync("hasLogin");
    if(hasLogin == null || hasLogin == false) return false;
    else return true;
  },

  globalData: {
    userInfo: null,
    hasLogin: false
  }
})